﻿<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<%@ include file="/commons/tabs.jsp"%>
<%@ include file="/commons/validation.jsp"%>
<%@ include file="/commons/dateTime.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>批量缴费</title>
<script type="text/javascript" src="${ctx}/scripts/jquery.js"></script>
<script language="JavaScript" type="text/javascript"
	src=".${ctx}/js/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript" src="${ctx}/scripts/show.js"></script>
<script language="JavaScript" type="text/javascript"
	src="${ctx}/scripts/global.js"></script>
	
<link href="${ctx}/styles/listTable.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/styles/grid.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>

<link href="${ctx}/css/show.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/public.css" rel="stylesheet" type="text/css">
<link href="${ctx}/css/aux_window.css" rel="stylesheet" type="text/css">
<style type="text/css">
.bg_toolBar {
	border-left: 1px solid #bcbfd2;
	border-right: 1px solid #bcbfd2;
}

.checked {
	background-color: #feec8c;
}
</style>

<script type="text/javascript">

	//打开添加房间的页面
	function openAddPage(){
	    var url="${ctx}/charge_cashieringAction.do?method=goAddPage";
		top.windowOpen(url,"addPage","批量收费添加",300,430);
	}

	function check(obj){
		jQuery.noConflict();
		var resultStr = jQuery(obj).find("input[id='houseId']").val();
		jQuery('#itemForDelete').attr("value",resultStr);
		return;
	}
	
	function appendDataByName(houseNumber,ownerName,periodId,codeId){
		
		
		jQuery.ajax({
			type:'GET',
			async:true,
			url	:	'${ctx}/charge_cashieringAction.do?method=findDataByOwnerName&houseNumber='+encodeURI(encodeURI(houseNumber))+'&ownerName='+ encodeURI(encodeURI(ownerName))+'&periodId='+periodId+'&codeId='+codeId,
			dataType:'text',
			success:function(json){
				
				if( json == "null" || json==null || json=="" ||json==undefined){
					FailureAlert('没有未缴费！');
					findFrame('addPageIfm').hiddenLoading();
				}else if(json=="noSuchRoom"){
					FailureAlert('该房号不存在，请重新输入！');
					findFrame('addPageIfm').hiddenLoading();
				}else if(json=="ownerNotExist"){
					FailureAlert('用户不存在，请重新输入！');
					findFrame('addPageIfm').hiddenLoading();
				}else if(json=="noRecord"){
					FailureAlert('该业主在所选周期已结清费用，不需缴费！');
					findFrame('addPageIfm').hiddenLoading();
				}else if(json=="manageHouse"){
					FailureAlert('管理房请到前台缴费中处理！');
					findFrame('addPageIfm').hiddenLoading();
				}else if(json=="mergePayHouse"){
					FailureAlert('该房号已被合并为合并记账管理房，请到前台缴费中处理！');
					findFrame('addPageIfm').hiddenLoading();
				}else{

					findFrame('addPageIfm').windowClose();
					
					jQuery('#totalNumber').html("0");
					jQuery('#addButton').html("");
					var wholeList='<tbody id="table2"><input type="hidden" id="itemForDelete" value=""/>';
					var temp = json.toString().split(";");
					for(var i=0;i<temp.length-1;i++){
					var data = temp[i].split("|");
					var id = data[0];
					var periodId = data[1];
					var number = data[2];
					var owner = data[3];						
					var period =data[4];
					var buzzCode = data[5];
					var benjin = data[6];						
					var lateFee =data[7];
					var total = data[8];
					var child = '<tr class="grid checked" onclick="check(this)">'+
										'<td class="grid align_left idStyle" style="display:none;"><input type="hidden" id="houseId" value="'+id+'"/><input type="hidden" id="periodId" value="'+periodId+'"/></td>'+
										'<td class="grid align_left">'+number+'</td>'+
										'<td class="grid align_left">'+owner+'</td>'+
										'<td class="grid align_left periodStyle">'+period+'</td>'+
										'<td class="grid align_left">'+buzzCode+'</td>'+
										'<td class="grid align_right" align="right">'+benjin+'</td>'+
										'<td class="grid align_right" align="right">'+lateFee+'</td>'+
										'<td class="grid align_right total" align="right">'+total+'</td></tr>';
					wholeList += child;
					jQuery('#totalNumber').html(parseFloat(jQuery('#totalNumber').html()) + parseFloat(total));
				}
				    wholeList += '</tbody>';
				jQuery('#table2').replaceWith(wholeList);	
				jQuery('#totalNumber').html(parseFloat(jQuery('#totalNumber').html()).toFixed(2));
				}
			},
			error:function(error){
				FailureAlert('请求出错,请重试');
			}
		});
		//hiddenLoading();
	}
	
	
	function deleteCheckedRecord(){
		jQuery.noConflict();
		
		var checkedEle = jQuery('#itemForDelete');
		var idpairs = checkedEle.val();

		jQuery('#totalNumber').html("0");
		if( idpairs == "null" || idpairs==null || idpairs=="" ||idpairs==undefined){
			FailureAlert("没有项目要删除！");
			return;
		}
		jQuery.ajax({
					type:'GET',
					async:false,
					url	:"${ctx}/charge_cashieringAction.do?method=deleteCacheBeforeBatchPay&ids="+checkedEle.val(),	
					dataType:'text',
			success:function(json){			    
				if( json == "null" || json==null || json=="" ||json==undefined){
					
				}else if(json=='periodExistError'){
					FailureAlert('不允许重复添加!');
					
				}else if(json=='periodConflictError'){
					FailureAlert('该添加项目的缴费周期与已添加项目有冲突!');
					
				}else{
					
					jQuery('#totalNumber').html("0");
					var wholeList='<tbody id="table2"><input type="hidden" id="itemForDelete" value=""/>';
					var temp = json.toString().split(";");
					if(temp.length <= 1){
						jQuery('#addButton').html('<a href="javascript:void openAddPage();" onFocus="this.blur()"><img src="${ctx}/images/ico_addData.gif" alt="添加" border="0" align="absbottom"></a>');
					}
					for(var i=0;i<temp.length-1;i++){
					var data = temp[i].split("|");
					var id = data[0];
					var periodId = data[1];
					var number = data[2];
					var owner = data[3];						
					var period =data[4];
					var buzzCode = data[5];
					var benjin = data[6];						
					var lateFee =data[7];
					var total = data[8];
					var child = '<tr class="grid checked" onclick="check(this)">'+
										'<td class="grid align_left idStyle" style="display:none;"><input type="hidden" id="houseId" value="'+id+'"/><input type="hidden" id="periodId" value="'+periodId+'"/></td>'+
										'<td class="grid align_left">'+number+'</td>'+
										'<td class="grid align_left">'+owner+'</td>'+
										'<td class="grid align_left periodStyle">'+period+'</td>'+
										'<td class="grid align_left">'+buzzCode+'</td>'+
										'<td class="grid align_right" align="right">'+benjin+'</td>'+
										'<td class="grid align_right" align="right">'+lateFee+'</td>'+
										'<td class="grid align_right total" align="right">'+total+'</td></tr>';
					wholeList += child;
					jQuery('#totalNumber').html(parseFloat(jQuery('#totalNumber').html()) + parseFloat(total));
				}
				    wholeList += '</tbody>';
				jQuery('#table2').replaceWith(wholeList);	
				jQuery('#totalNumber').html(parseFloat(jQuery('#totalNumber').html()).toFixed(2));
				}
			},
			error:function(error){
				FailureAlert('请求出错,请重试');
			}
		});
		
	}
	
	function doConfirmSaveCharge(){
	
		var isExistItem = jQuery('#table2').find("tr");

		if(isExistItem.length==0){
			FailureAlert('没有项目需要进行缴费，请添加！');
		}else{
			AskConfirm("确定对所有已添加项进行批量缴费吗？","listPageIfm","saveCharge");
		}
	}
	
	function saveCharge(){
		showLoading("批量缴费正在处理中，请稍候...");
		jQuery.ajax({
					type:'GET',
					url	:"${ctx}/charge_cashieringAction.do?method=addBatchPayBill",
					dataType:'text',
					async:true,
					success:function(json){
						if(json=='success'){
							SuccessAlert('缴费成功');
							windowClose();
						}else{
							FailureAlert('批量缴费失败,请重试或与管理员联系!');
						}
					},
					error:function(error){
						FailureAlert('批量缴费失败,请重试!');
					}
		});
	}
	
	function closeCacheWindow(){

		jQuery.ajax({
					type:'GET',
					url	:"${ctx}/charge_cashieringAction.do?method=cleanBatchPayCache"				
				}
		);
		windowClose();

	}
	function cleanCacheForDelete(){
		jQuery.ajax({
					type:'GET',
					url	:"${ctx}/charge_cashieringAction.do?method=cleanBatchPayCache"				
					}
		);
	}
	
</script>


</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="window_head_outBg">
		<table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td><img src="${ctx}/images/ico_Advance.gif" width="16"
					height="16" align="absmiddle"> <span
					class="window_head_intext">批量收费</span></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="aux_header_line_1"></td>
	</tr>
	<tr>
		<td class="aux_header_line_2"></td>
	</tr>
	<tr>
		<td valign="middle" class="content">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td class="bg_toolBar">
				<table border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="toolbarico" id="addButton"><a href="javascript:void openAddPage();" onFocus="this.blur()"><img src="${ctx}/images/ico_addData.gif" alt="添加" border="0" align="absbottom"></a></td>
						<td class="toolbarico"><a href="#" onFocus="this.blur()"
							onclick="deleteCheckedRecord();"><img
							src="${ctx}/images/ico_delete.gif" alt="删除" border="0"
							align="absbottom"></a></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		<table width="100%" border="0" cellpadding="0" cellspacing="0"
			class="tab_line">
			<tr>
				<td valign="top">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">

					<tr>
						<td colspan="5">
						<table width="100%" border="0" cellspacing="0" cellpadding="0"
							id="crmGrid" class="gridControl gridArea">
							<tr>
								<td class="align_left"
									onMouseOver="this.className='grid_sort_on align_left'"
									onMouseOut="this.className='align_left'"><span
									class="grid grid_head_line">房号</span></td>
								<td width="12%" class="align_left"
									onMouseOver="this.className='grid_sort_on align_left'"
									onMouseOut="this.className='align_left'">业主</td>
								<td width="15%" class="align_left"
									onMouseOver="this.className='grid_sort_on align_left'"
									onMouseOut="this.className='align_left'"><span
									class="grid grid_head_line" onClick="swapPic2()">收费周期 <img
									src="${ctx}/images/ico_table_up.gif" name="randimg"
									id="randimg" /></span></td>
								<td width="20%" class="align_left"
									onMouseOver="this.className='grid_sort_on align_left'"
									onMouseOut="this.className='align_left'"><span
									class="grid grid_head_line">交易支付码</span></td>
								<td width="15%" class="align_right"
									onMouseOver="this.className='grid_sort_on align_right'"
									onMouseOut="this.className='align_center'"><span
									class="grid grid_head_line">本金金额(元)</span></td>
								<td width="12%" class="align_right"
									onMouseOver="this.className='grid_sort_on align_right'"
									onMouseOut="this.className='align_right'"><span
									class="grid grid_head_line">滞纳金(元)</span></td>
								<td width="12%" class="align_right"
									onMouseOver="this.className='grid_sort_on align_right'"
									onMouseOut="this.className='align_right'"><span
									class="grid">费用余额(元)</span></td>
							</tr>
						</table>
						<div
							style="height: 300px; overflow-y: auto; overflow-x: hidden; background-color: #FFF;">
						<table width="100%" border="0" cellspacing="0" cellpadding="0"
							class='gridData2'>
							<tbody id="table2">

							</tbody>
						</table>
						</div>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr class="grid">
								<td colspan="4" class="chareg_hj"><strong>合计：</strong></td>
								<td colspan="3" align="right" class="chareg_hj"><span
									class="font_red" id="totalNumber">0</span><strong>元</strong>&nbsp;</td>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="window_footer">
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td>
				<table border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="buttonOffLeft" id="btn1_21"></td>
						<td class="buttonOffMiddle" id="btn1_22"
							onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)"
							onblur="btn_change(2)" onclick="doConfirmSaveCharge();"><img
							src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14"
							border="0" align="absbottom"> 保 存</td>
						<td class="buttonOffRight" id="btn1_23"></td>
					</tr>
				</table>
				</td>
				<td class="btn_between_space"></td>
				<td>
				<table border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="buttonOffLeft" id="btn1_31"></td>
						<td class="buttonOffMiddle" id="btn1_32" onClick="closeCacheWindow();"
							onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)"
							onblur="btn_change(3)"><img
							src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14"
							border="0" align="absbottom"> 关 闭</td>
						<td class="buttonOffRight" id="btn1_33"></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</body>
</html>